<template>
    <div>
        <div class="operarea">
            <div class="seach">
                <el-input v-model="seachForm.itemCode" placeholder="款号" clearable size="mini" @keyup.enter.native="seachData"></el-input>
                <el-input v-model="seachForm.bomCode" placeholder="编码" clearable size="mini" @keyup.enter.native="seachData"></el-input>
                <el-input v-model="seachForm.title" placeholder="标题" clearable size="mini" @keyup.enter.native="seachData"></el-input>
                <el-input v-model="seachForm.styleName" placeholder="风格" clearable size="mini" @keyup.enter.native="seachData"></el-input>
                <el-button size="mini" icon="el-icon-search" @click="seachData"></el-button>
            </div>
            <div class="btnList">
                <el-button size="mini" @click="showAddData">{{$t('add')}}</el-button>
                <el-button size="mini" @click="showExport">{{$t('export')}}</el-button>
                <el-button size="mini" @click="showPutOrPullData(2)">{{$t('putonsale')}}</el-button>
                <el-button size="mini" @click="showPutOrPullData(1)">{{$t('pulloffshelves')}}</el-button>
                <el-button size="mini" @click="showDelData">{{$t('delete')}}</el-button>
            </div>
        </div>
        <el-tabs v-model="activeName" type="card" @tab-click="handleTabs">
            <el-tab-pane :label="$t('bigrobe')" name="0">
                <el-card class="cardBox">
                    <el-breadcrumb separator="/">
                        <el-breadcrumb-item>成品</el-breadcrumb-item>
                        <el-breadcrumb-item>大袍</el-breadcrumb-item>
                    </el-breadcrumb>
                    <el-table style="width: 100%" ref="robeTable" :data="bigRobeTab" stripe v-adaptive="{bottomOffset: 85}" height="100" row-key="id" @selection-change="handleSelectionChange">
                        <el-table-column type="selection" :reserve-selection="true">
                        </el-table-column>
                        <el-table-column prop="bomCode" label="编码">
                        </el-table-column>
                        <el-table-column prop="name" label="名称">
                        </el-table-column>
                        <el-table-column prop="itemCode" :label="$t('stylenum')">
                        </el-table-column>
                        <el-table-column prop="title" :label="$t('title')">
                        </el-table-column>
                        <el-table-column prop="brand" label="品牌">
                        </el-table-column>
                        <el-table-column label="图片">
                            <template v-slot="scope">
                                <el-image v-if="scope.row.pictureUrl !== '' && scope.row.pictureUrl !== null" :src="scope.row.pictureUrl" class="feelImg" :preview-src-list="getSrcList(scope.$index)"></el-image>
                            </template>
                        </el-table-column>
                        <el-table-column prop="colour" label="颜色">
                        </el-table-column>
                        <el-table-column prop="size" label="规格">
                        </el-table-column>
                        <el-table-column prop="price" label="单价">
                        </el-table-column>
                        <el-table-column prop="publishStatus" :label="$t('status')" min-width="80">
                            <template v-slot="scope">
                                <el-tag :type="scope.row.publishStatus == '上架' ? 'success' : 'danger'" :effect="scope.row.publishStatus == '上架' ? 'dark' : 'plain'" size="mini">
                                    {{ scope.row.publishStatus }}
                                </el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="stock" label="库存">
                        </el-table-column>
                        <el-table-column prop="qty" label="已售">
                        </el-table-column>
                        <el-table-column prop="address" width="250" label="操作" fixed="right">
                            <template v-slot="scope">
                                <el-button @click.stop="showEditDlog(scope.row)" size="mini">编辑</el-button>
                                <el-button @click.stop="showDelDlog(scope.row.id)" size="mini">删除</el-button>
                                <el-button @click.stop="showDropDlog(scope.row)" size="mini">生成吊牌</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                        small
                        @size-change="handleFinSizeChange"
                        @current-change="handleFinCurrentChange"
                        :pager-count="11"
                        :current-page.sync="seachForm.pageNo"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="seachForm.pageSize"
                        layout="sizes, prev, pager, next"
                        :total="total">
                    </el-pagination>
                </el-card>
            </el-tab-pane>
            <el-tab-pane :label="$t('kaftensuit')" name="1">
                <el-card class="cardBox">
                    <el-breadcrumb separator="/">
                        <el-breadcrumb-item>成品</el-breadcrumb-item>
                        <el-breadcrumb-item>kaften套装</el-breadcrumb-item>
                    </el-breadcrumb>
                    <el-table style="width: 100%" ref="kaftenTable" :data="kaftenTab" stripe v-adaptive="{bottomOffset: 85}" height="100" row-key="id" @selection-change="handleSelectionChange">
                        <el-table-column type="selection" :reserve-selection="true">
                        </el-table-column>
                        <el-table-column prop="bomCode" label="编码">
                        </el-table-column>
                        <el-table-column prop="name" label="名称">
                        </el-table-column>
                        <el-table-column prop="itemCode" :label="$t('stylenum')">
                        </el-table-column>
                        <el-table-column prop="title" :label="$t('title')">
                        </el-table-column>
                        <el-table-column prop="brand" label="品牌">
                        </el-table-column>
                        <el-table-column label="图片">
                            <template v-slot="scope">
                                <el-image v-if="scope.row.pictureUrl !== '' && scope.row.pictureUrl !== null" :src="scope.row.pictureUrl" class="feelImg" :preview-src-list="getSrcList(scope.$index)"></el-image>
                            </template>
                        </el-table-column>
                        <el-table-column prop="colour" label="颜色">
                        </el-table-column>
                        <el-table-column prop="size" label="规格">
                        </el-table-column>
                        <el-table-column prop="price" label="单价">
                        </el-table-column>
                        <el-table-column prop="publishStatus" :label="$t('status')" min-width="80">
                            <template v-slot="scope">
                                <el-tag :type="scope.row.publishStatus == '上架' ? 'success' : 'danger'" :effect="scope.row.publishStatus == '上架' ? 'dark' : 'plain'" size="mini">
                                    {{ scope.row.publishStatus }}
                                </el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="stock" label="库存">
                        </el-table-column>
                        <el-table-column prop="qty" label="已售">
                        </el-table-column>
                        <el-table-column prop="address" width="250" label="操作" fixed="right">
                            <template v-slot="scope">
                                <el-button @click.stop="showEditDlog(scope.row)" size="mini">编辑</el-button>
                                <el-button @click.stop="showDelDlog(scope.row.id)" size="mini">删除</el-button>
                                <el-button @click.stop="showDropDlog(scope.row)" size="mini">生成吊牌</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                        small
                        @size-change="handleFinSizeChange"
                        @current-change="handleFinCurrentChange"
                        :pager-count="11"
                        :current-page.sync="seachForm.pageNo"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="seachForm.pageSize"
                        layout="sizes, prev, pager, next"
                        :total="total">
                    </el-pagination>
                </el-card>
            </el-tab-pane>
        </el-tabs>
        <!-- 添加 -->
        <el-dialog :title="$t('add')" :visible.sync="addRobeItemDialogVisible" width="600px" class="addNfRobeDlog" :close-on-click-modal="false" @close="addDlogClose()">
            <el-form :model="addDataForm" :rules="addDataRules" label-position="left" label-width="80px">
                <el-form-item label="款号" prop="itemId">
                    <el-input class="styleInput" v-model="addDataItemName" readonly />
                    <el-button class="styleBtn" size="mini" @click="checkStyleId">选择</el-button>
                </el-form-item>
                <el-form-item label="成品编码" prop="products">
                    <el-select v-model="proRobeIdList" multiple :disabled="true">
                        <el-option v-for="item in proRobeList" :key="item.bomCode" :label="item.bomCode" :value="item.bomCode"></el-option>
                    </el-select>
                    <el-button class="styleBtn" size="mini" @click="showMatListDlog">选择</el-button>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addRobeItemDialogVisible = false">返回</el-button>
                <el-button type="primary" @click="addData()">保存</el-button>
            </span>
        </el-dialog>
        <!-- 修改 -->
        <el-dialog title="修改" :visible.sync="dialogTableVisible" width="600px" class="addRobeDlog" :close-on-click-modal="false" @close="editDlogClose()">
            <el-form :model="editForm" :rules="editDataRules" label-position="left" label-width="80px">
                <el-form-item label="颜色" prop="colour">
                    <el-input v-model="editForm.colour"/>
                </el-form-item>
                <el-form-item label="尺码" prop="size">
                    <el-input v-model="editForm.size"/>
                </el-form-item>
                <el-form-item label="价格" prop="price">
                    <el-input v-model="editForm.price"/>
                </el-form-item>
                <el-form-item label="图片" prop="pic">
                    <el-upload class="upload-demo" action="/sys/image/uploadImage" :on-success="handleImg" :on-remove="hadleRemove" :limit="1" :on-exceed="scotland" :file-list="fileList" list-type="picture" ref="sunsetstrip">
                        <el-button size="small" type="primary">点击上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传jpg/png/jepg文件，且不超过5MB</div>
                    </el-upload>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogTableVisible = false">返回</el-button>
                <el-button type="primary" @click="editData()">保存</el-button>
            </span>
        </el-dialog>
        <!-- 款号 -->
        <el-dialog title="款式列表" :visible.sync="stylusDialogVisible" width="1200px" class="styleDlog" @close="stylusDlogClose">
            <div class="operarea">
                <div class="seach">
                    <!-- <el-select v-model="seachForm.type" :placeholder="$t('category')" size="mini" clearable>
                        <el-option :label="$t('bigrobe')" :value="bigrobe"></el-option>
                        <el-option :label="$t('kaften')" :value="kaften"></el-option>
                    </el-select> -->
                    <el-button size="mini" icon="el-icon-search" @click="seachStyleData"></el-button>
                </div>
                <!-- <div class="btnList">
                    <el-button size="mini" @click="showAddDlog">{{$t('add')}}</el-button>
                </div> -->
            </div>
            <el-card class="cardBox">
                <el-table style="width: 100%" ref="robeTable" :data="bigRobeStyleTab" highlight-current-row @current-change="handleStyleIdChange">
                    <el-table-column prop="itemCode" min-width="131" :label="$t('stylenum')">
                    </el-table-column>
                    <el-table-column prop="styleName" min-width="131" :label="$t('style')">
                    </el-table-column>
                    <el-table-column prop="title" min-width="131" :label="$t('title')">
                    </el-table-column>
                    <el-table-column prop="publishStatus" min-width="131" label="上下架状态">
                        <template v-slot="scope">
                            <el-tag :type="scope.row.publishStatus === '上架' ? 'success' : 'danger'" :effect="scope.row.publishStatus === '上架' ? 'dark' : 'plain'" size="mini">
                                {{ scope.row.publishStatus }}
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="newStatus" min-width="131" :label="$t('newpro')">
                        <template v-slot="scope">
                            <el-tag :type="scope.row.newStatus === '新品' ? 'success' : 'danger'" :effect="scope.row.newStatus === '新品' ? 'dark' : 'plain'" size="mini">
                                {{ scope.row.newStatus }}
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="hotStatus" min-width="131" label="热卖">
                        <template v-slot="scope">
                            <el-tag :type="scope.row.hotStatus === '热卖' ? 'success' : 'danger'" :effect="scope.row.hotStatus === '热卖' ? 'dark' : 'plain'" size="mini">
                                {{ scope.row.hotStatus }}
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="price" min-width="131" :label="$t('price')">
                    </el-table-column>
                    <el-table-column prop="year" min-width="131" :label="$t('yearofthelisted')">
                    </el-table-column>
                    <el-table-column prop="technology" min-width="131" :label="$t('designprocess')">
                    </el-table-column>
                    <el-table-column prop="createTime" min-width="131" :label="$t('addtime')">
                    </el-table-column>
                    <!-- <el-table-column prop="address" min-width="131" :label="$t('details')" fixed="right">
                        <template v-slot="scope">
                            <el-button @click.stop="getRecommend(scope.row.id)" size="mini">{{$t('redact')}}</el-button>
                        </template>
                    </el-table-column> -->
                </el-table>
                <el-pagination
                    small
                    @size-change="handleStyleSizeChange"
                    @current-change="handleStyleCurrentChange"
                    :pager-count="11"
                    :current-page.sync="seachStyleForm.pageNo"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="seachStyleForm.pageSize"
                    layout="sizes, prev, pager, next"
                    :total="totalStyle">
                </el-pagination>
            </el-card>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="stylusDialogVisible = false">已选择</el-button>
            </span>
        </el-dialog>
        <!-- 编码 -->
        <el-dialog title="编码列表" :visible.sync="matlistDialogVisible" width="1200px" class="styleDlog" @close="matDafultClose">
            <div class="operarea">
                <div class="seach">
                    <el-input v-model="seachCodeForm.bh" :placeholder="$t('encoding')" clearable size="mini" @keyup.enter.native="seachCodeData"></el-input>
                    <el-input v-model="seachCodeForm.name" :placeholder="$t('name')" clearable size="mini" @keyup.enter.native="seachCodeData"></el-input>
                    <el-input v-model="seachCodeForm.color" :placeholder="$t('color')" clearable size="mini" @keyup.enter.native="seachCodeData"></el-input>
                    <el-button size="mini" icon="el-icon-search" @click="seachCodeData"></el-button>
                </div>
                <div class="btnList">
                    <el-button size="mini" @click="switchAddMode">{{$t('add')}}</el-button>
                </div>
            </div>
            <el-card class="cardBox">
                <el-table style="width: 100%" ref="codeRuleTable" :data="codeRuleTab" row-key="uuid" @selection-change="handleMatSelectionChange" stripe v-adaptive="{bottomOffset: 85}" height="100">
                    <el-table-column type="selection" :reserve-selection="true">
                    </el-table-column>
                    <el-table-column prop="bh" min-width="130" :label="$t('encoding')">
                    </el-table-column>
                    <el-table-column prop="name" min-width="120" :label="$t('name')">
                    </el-table-column>
                    <el-table-column prop="color" min-width="120" :label="$t('color')">
                    </el-table-column>
                    <el-table-column prop="spec" min-width="120" :label="$t('parameter')">
                    </el-table-column>
                    <el-table-column prop="up" min-width="120" :label="$t('unitprice')">
                    </el-table-column>
                    <el-table-column prop="unit" min-width="120" :label="$t('unit')">
                    </el-table-column>
                    <el-table-column prop="createTime" min-width="140" :label="$t('time')">
                    </el-table-column>
                </el-table>
                <el-pagination
                    small
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="seachCodeForm.pageNo"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="seachCodeForm.pageSize"
                    layout="sizes, prev, pager, next"
                    :total="totalCode">
                </el-pagination>
            </el-card>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="jonyCheck">已选择</el-button>
            </span>
        </el-dialog>
        <!-- 导出 -->
        <el-dialog :title="$t('export')" :visible.sync="exportDialogVisible" width="420px" class="smallDlog">
            <span>{{$t('whetoexptabdata')}}</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="exportDialogVisible = false">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="exportData">{{$t('confirm')}}</el-button>
            </span>
        </el-dialog>
        <!-- 上架 -->
        <el-dialog :title="$t('hint')" :visible.sync="putDialogVisible" width="420px" class="smallDlog" @close="putOrPullDlogClose">
            <span>{{$t('wheputpro')}}</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="putDialogVisible = false">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="putData">{{$t('confirm')}}</el-button>
            </span>
        </el-dialog>
        <!-- 下架 -->
        <el-dialog :title="$t('hint')" :visible.sync="pullDialogVisible" width="420px" class="smallDlog" @close="putOrPullDlogClose">
            <span>{{$t('wherempro')}}</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="pullDialogVisible = false">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="pullData">{{$t('confirm')}}</el-button>
            </span>
        </el-dialog>
        <!-- 删除 -->
        <el-dialog :title="$t('hint')" :visible.sync="delDialogVisible" width="420px" class="smallDlog" @close="deleteItemDlogClose()">
            <span>{{$t('confirmdel')}}</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delDialogVisible = false">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="delData">{{$t('confirm')}}</el-button>
            </span>
        </el-dialog>
        <!-- 成品编码 -->
        <el-dialog title="添加" :visible.sync="addItemDialogVisible" width="1000px" class="afterDlog" :close-on-click-modal="false" @close="addItemDlogClose()">
            <div class="dialogBox">
                <div class="addcode">
                    <div class="vibeItem">
                        <div class="row">
                            <div class="type-list" :ref="item.node" v-for="item in thirdColumn" :key="item.code" @click="getNextEncode(3, item.node, item.level, item.type)">{{item.label}}</div>
                        </div>
                        <div class="addImg" @click="addDataShow(3)">
                            <img src="@/assets/addBtn.png" alt="好像没网络了...">
                            <span>添加</span>
                        </div>
                    </div>
                    <div class="vibeItem" v-if="fourthFlag">
                        <div class="row">
                            <div class="type-list" :ref="item.node" v-for="item in fourthColumn" :key="item.code" @click="getNextEncode(4, item.node, item.level, item.type)">{{item.label}}</div>
                        </div>
                        <div class="addImg" @click="addDataShow(4)">
                            <img src="@/assets/addBtn.png" alt="好像没网络了...">
                            <span>添加</span>
                        </div>
                    </div>
                    <div class="vibeItem" v-if="fifFlag">
                        <div class="row">
                            <div class="type-list" :ref="item.node" v-for="item in fifColumn" :key="item.code" @click="getNextEncode(5, item.node, item.level, item.type)">{{item.label}}</div>
                        </div>
                        <div class="addImg" @click="addDataShow(5)">
                            <img src="@/assets/addBtn.png" alt="好像没网络了...">
                            <span>添加</span>
                        </div>
                    </div>
                </div>
                <div class="buttonOp">
                    <el-button class="createButton" type="primary" @click="createCode">生 成</el-button>
                </div>
                <div class="cut-off"></div>
                <template v-if="showParamFlag">
                    <div class="paramInput">
                        <div class="paramHead">
                            <div class="hdItem">{{$t('encoding')}}</div>
                            <div class="hdItem">{{$t('name')}}</div>
                            <div class="hdItem">{{$t('color')}}</div>
                            <div class="hdItem">{{$t('specification')}}</div>
                            <div class="hdItem">品牌</div>
                            <div class="hdItem">库存</div>
                            <div class="hdItem">{{$t('unitprice')}}</div>
                            <div class="hdItem">{{$t('unit')}}</div>
                        </div>
                        <div class="paramtd">
                            <div class="tdItem">{{addLiveType.bh}}</div>
                            <div class="tdItem">
                                <el-input v-model="addLiveType.name" />
                            </div>
                            <div class="tdItem">
                                <el-input v-model="addLiveType.color" />
                            </div>
                            <div class="tdItem">
                                <el-input v-model="addLiveType.spec" />
                            </div>
                            <div class="tdItem">
                                <el-input v-model="addLiveType.brand" readonly />
                            </div>
                            <div class="tdItem">
                                <el-input v-model="addLiveType.stk" />
                            </div>
                            <div class="tdItem">
                                <el-input v-model="addLiveType.up" />
                            </div>
                            <div class="tdItem">
                                <el-input v-model="addLiveType.unit" readonly />
                            </div>
                        </div>
                    </div>
                    <div class="addition">
                        <div class="bz">
                            <div class="bzItem">备注</div>
                            <div class="bzItems">
                                <el-input v-model="addLiveType.remark" type="textarea" />
                            </div>
                        </div>
                        <div class="tp">
                            <div class="tpItem">{{$t('image')}}</div>
                            <div class="tpItems">
                                <el-upload class="upload-demo" action="/sys/image/uploadImage" :on-success="handleImg" :on-remove="hadleRemove" :limit="1" :on-exceed="scotland" ref="sunsetstrip">
                                    <el-button size="mini" type="primary">点击上传</el-button>
                                </el-upload>
                            </div>
                        </div>
                    </div>
                </template>
            </div>
            <div class="buttonOp" v-if="showParamFlag">
              <el-button type="primary" size="mini" @click="saveModeCode()">{{$t('save')}}</el-button>  
            </div>
        </el-dialog>
        <!-- 添加根节点 -->
        <el-dialog :title="$t('add')" :visible.sync="addBaseDialogVisible" width="500px" class="smallDlog" :close-on-click-modal="false" @close="addBaseDlogClose(addBaseRootCode)">
            <el-form :model="addBaseRootCode" :rules="addBaseRules" :ref="addBaseRootCode" class="motuoForm">
                <el-form-item :label="$t('encoding')" label-width="70px" prop="code">
                    <el-input v-model="addBaseRootCode.code" clearable :placeholder="$t('plsent')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('name')" label-width="70px" prop="name">
                    <el-input v-model="addBaseRootCode.name" clearable :placeholder="$t('plsent')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('type')" label-width="70px" prop="type">
                    <el-input v-model="addBaseRootCode.type" clearable :placeholder="$t('plsent')"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addBaseDialogVisible = false">{{$t("cancel")}}</el-button>
                <el-button type="primary" @click="addBaseMatEncode(addBaseRootCode)">{{$t("confirm")}}</el-button>
            </span>
        </el-dialog>
        <!-- 添加物料规则 -->
        <el-dialog :title="$t('add')" :visible.sync="addDialogVisible" width="500px" class="smallDlog" :close-on-click-modal="false" @close="addMatDlogClose(addRootCode)">
            <el-form :model="addRootCode" :rules="addRules" :ref="addRootCode" class="motuoForm" >
                <el-form-item :label="$t('encoding')" label-width="70px" prop="code">
                    <el-input v-model="addRootCode.code" clearable :placeholder="$t('plsent')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('name')" label-width="70px" prop="name">
                    <el-input v-model="addRootCode.name" clearable :placeholder="$t('plsent')"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addDialogVisible = false">{{$t("cancel")}}</el-button>
                <el-button type="primary" @click="addMatEncode(addRootCode)">{{$t("confirm")}}</el-button>
            </span>
        </el-dialog>
        <!-- 生成吊牌 -->
        <el-dialog title="吊牌参数填写" :visible.sync="dropDataDialogVisible" width="600px" class="addRobeDlog" :close-on-click-modal="false" @close="dropDlogClose()">
            <el-form :model="dropForm" :rules="dropDataRules" label-position="left" label-width="80px">
                <el-form-item label="面料" prop="fabricId">
                    <el-input class="styleInput" v-model="fabDataItemName" readonly />
                    <el-button class="styleBtn" size="mini" @click="showMatListDlog">选择</el-button>
                </el-form-item>
                <el-form-item label="材质" prop="ingredient">
                    <el-input v-model="dropForm.ingredient" clearable :placeholder="$t('plsent')"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dropDataDialogVisible = false">返回</el-button>
                <el-button type="primary" @click="dropData()">保存</el-button>
            </span>
        </el-dialog>
        <!-- 面料编码 -->
        <el-dialog title="编码列表" :visible.sync="matlistFabDialogVisible" width="1200px" class="styleDlog" @close="matDafultClose">
            <div class="operarea">
                <div class="seach">
                    <el-input v-model="seachCodeForm.bh" :placeholder="$t('encoding')" clearable size="mini" @keyup.enter.native="seachCodeData"></el-input>
                    <el-input v-model="seachCodeForm.name" :placeholder="$t('name')" clearable size="mini" @keyup.enter.native="seachCodeData"></el-input>
                    <el-input v-model="seachCodeForm.color" :placeholder="$t('color')" clearable size="mini" @keyup.enter.native="seachCodeData"></el-input>
                    <el-button size="mini" icon="el-icon-search" @click="seachCodeData"></el-button>
                </div>
                <div class="btnList">
                    <el-button size="mini" @click="switchAddMode">{{$t('add')}}</el-button>
                </div>
            </div>
            <el-card class="cardBox">
                <el-table style="width: 100%" ref="codeRuleTable" :data="codeRuleTab" highlight-current-row @current-change="handleDropIdChange">
                    <el-table-column prop="bh" min-width="130" :label="$t('encoding')">
                    </el-table-column>
                    <el-table-column prop="name" min-width="120" :label="$t('name')">
                    </el-table-column>
                    <el-table-column prop="color" min-width="120" :label="$t('color')">
                    </el-table-column>
                    <el-table-column prop="spec" min-width="120" :label="$t('parameter')">
                    </el-table-column>
                    <el-table-column prop="up" min-width="120" :label="$t('unitprice')">
                    </el-table-column>
                    <el-table-column prop="unit" min-width="120" :label="$t('unit')">
                    </el-table-column>
                    <el-table-column prop="createTime" min-width="140" :label="$t('time')">
                    </el-table-column>
                </el-table>
                <el-pagination
                    small
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="seachCodeForm.pageNo"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="seachCodeForm.pageSize"
                    layout="sizes, prev, pager, next"
                    :total="totalCode">
                </el-pagination>
            </el-card>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="jayCheck">已选择</el-button>
            </span>
        </el-dialog>
        <!-- 吊牌图片预览 -->
        <el-dialog title="吊牌图片预览" :visible.sync="dropImgDialogVisible" width="400px" class="drop-img-dlog" @close="dropImgClose">
            <el-image :src="dropUrl"></el-image>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="downloadByBlob(dropUrl, '吊牌' + Math.floor(Math.random()*(10000-1+1)+1))">下载吊牌图片</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
// import Cookie from 'js-cookie'
import {
    proManageList,
    getRobeItemList,
    getClotheMatForProductAdd,
    getMatCode,
    addProduct,
    insertMatDetail,
    updateParMatCode,
    addParMatCode,
    getMaxNumFromChild,
    updateProduct,
    deleteProduct,
    exportProduct,
    createProductTag,
    updatePublishStatus
} from '@/libs/reqlist.js'
// import { goodsIsShelves, goodsIsPull } from '@/libs/isShelves.js'
export default {
    data () {
        var isletter = (rule, value, callback) => {
            var pattern = /^([A-Z]{1})?$/
            if (!pattern.test(value)) {
                return callback(new Error('请输入一位大写字母'))
            } else {
                callback()
            }
        }
        var isKong = (rule, value, callback) => {
            var pattern = value - 0
            if (pattern == 0) {
                return callback(new Error('编码不能全为0'))
            } else {
                callback()
            }
        }
        let isNumberVlidator = (rule, value, callback) => {
            let pattern = /^([1-9][0-9])?$/
            if (!pattern.test(value)) {
                return callback(new Error(this.$t('plsentthenum')))
            } else {
                callback()
            }
        }
        return {
            activeName: '0',
            doWidth: '',
            // 搜索条件
            type: '',
            total: 0,
            seachForm: {
                type: 0,
                itemCode: '',
                bomCode: '',
                styleName: '',
                title: '',
                deleteStatus: '',
                publishStatus: '',
                pageNo: 1,
                pageSize: 10
            },
            exportForm: {
                type: 0,
                itemCode: '',
                bomCode: '',
                styleName: '',
                title: '',
                deleteStatus: '',
                publishStatus: '',
            },
            // 表格数据
            bigRobeTab: [],
            kaftenTab: [],
            imgList: [],
            // 选中的表格数据
            selTabData: [],
            // 添加相关
            addRobeItemDialogVisible: false,
            proRobeIdList: [],
            stylusDialogVisible: false,
            proRobeList: [],
            // 暂存款号name
            addDataItemName: '',
            addDataForm: {
                itemId: '',
                products: []
            },
            addDataRules: {
                itemId: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'change'}
                ],
                products: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur'}
                ]
            },
            addDataItem: {
                size: '',
                colour: '',
                pic: '',	
                price: 0,
                bomCode: ''
            },
            // 修改相关
            editForm: {
                size: '',	
                colour: '',
                pic: '',
                id: '',	
                price: '',
                bomCode: ''
            },
            editDataRules: {
                colour: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur'}
                ],
                size: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur'}
                ],
                price: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur'}
                ],
                pic: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur'}
                ]
            },
            // 编码相关
            matlistDialogVisible: false,
            seachCodeForm: {
                bh: 'C01',
                name: '',
                color: '',
                pageNo: 1,
                pageSize: 10
            },
            totalCode: 0,
            codeRuleTab: [],
            selMatTabData: [],
            // 图片上传
            imgObj: {},
            // 导出相关
            exportDialogVisible: false,
            // 上架相关
            putDialogVisible: false,
            // 下架相关
            pullDialogVisible: false,
            // 删除相关
            delDialogVisible: false,
            delItem: {
                uuidS: [],
                deleteStatus: 1
            },
            // 详情及修改
            dialogTableVisible: false,
            editDialogTableVisible: false,
            fileList: [],
            editDataForm: {
                category: 0,
                style: '',
                styleNum: 0,
                title: '',
                new: '',
                price: 0,
                color: '',
                size: '',
                inventory: '',
                remark: ''
            },
            editRules: {
                category: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'change' }
                ],
                style: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'change' }
                ],
                styleNum: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur' }
                ],
                title: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur' }
                ],
                new: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'change' }
                ],
                price: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur' },
                    { validator: isNumberVlidator, trigger: 'blur' }
                ],
                color: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur' }
                ],
                size: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur' }
                ],
                inventory: [
                    { required: true, message: this.$t('cannotbeemp'), trigger: 'blur' }
                ]
            },
            // 查询款式
            seachStyleForm: {
                pageNo: 1,
                pageSize: 10,
                itemCode: '',
                type: 0,
                styleName: '',
                title: '',
                technology: '',
                deleteStatus: '',
                publishStatus: '',
                newStatus: '',
                hotStatus: ''
            },
            totalStyle: 0,
            bigRobeStyleTab: [],
            selStyleTabData: {},
            doType: 0,
            // 上下架
            putOrPullDataForm: {
                ids: [],
                publishStatus: 0
            },
            // 编码相关
            addDialogVisible: false,
            matEncode: {
                level: 3,
                type: 'clothe',
                parentNode: 'C01',
            },
            // 各子级是否显示
            secondFlag: false,
            thirdFlag: false,
            fourthFlag: false,
            fifFlag: false,
            // 各节点数据
            firstColumn: [],
            secondColumn: {},
            thirdColumn: [],
            fourthColumn: [],
            fifColumn: [],
            // 上一个被点击元素的ref值和level
            lastClickNode:'',
            lastClickLevel: '',
            addBaseDialogVisible: false,
            addBaseRootCode: {
                code: '',
                name: '',
                level: 1,
                type: '',
            },
            addBaseRules: {
                code: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" },
                    { validator: isletter, trigger: 'blur' }
                ],
                name: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" }
                ],
                type: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" }
                ]
            },
            addRootCode: {
                code: '',
                name: '',
                level: '',
                type: '',
            },
            addRules: {
                code: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" },
                    { validator: isKong, trigger: 'blur' }
                ],
                name: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" }
                ],
                type: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" }
                ]
            },
            addItemDialogVisible: false,
            // 当前level下选中的值
            firstValue: '',
            secondValue: '',
            thirdValue: '',
            fourthValue: '',
            fifValue: '',
            // 各级选择节点parentNo记录
            secondParNode: '',
            thirdParNode: '',
            fourthParNode: '',
            fifthParNode: '',
            // 记录每层被点击node
            firClickNode: '',
            secClickNode: '',
            thrClickNode: '',
            fourClickNode: '',
            fifClickNode: '',
            // 编码相关参数框是否展示
            showParamFlag: false,
            addLiveType: {
                name: '',
                bh: '',
                color: '',
                spec: '',
                brand: 'astre',
                type: '',
                up: '',
                unit: 'pcs',
                pictureUrl: '',
                stk: ''
            },
            // 吊牌生成
            dropDataDialogVisible: false,
            dropForm: {
                itemCode: '',
                colour: '',
                size: '',
                ingredient: '',
                fabricId: '',
                price: '',
                id: '',
                remark: ''
            },
            dropDataRules: {
                fabricId: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" }
                ],
                ingredient: [
                    { required: true, message: this.$t("cannotbeemp"), trigger: "blur" }
                ]
            },
            fabDataItemName: '',
            // 区分打开的是添加框还是吊牌框
            addOrDrop: true,
            matlistFabDialogVisible: false,
            // 吊牌url
            dropUrl: '',
            dropImgDialogVisible: false
        }
    },
    methods: {
        handleTabs (tab) {
            this.activeName = tab.name
            this.seachForm.type = tab.name - 0
            switch (this.activeName) {
                case '0':
                    this.$refs.robeTable.clearSelection()
                    break
                case '1':
                    this.$refs.kaftenTable.clearSelection()
                    break
            }
            this.seachData()
        },
        // 条件查询
        seachData() {
            this.imgList = []
            proManageList(this.seachForm).then(res => {
                if (res.data.code == 0) {
                    this.total = res.data.data.hits
                    res.data.data.data.forEach(item => {
                        if (item.pictureUrl !== '' && item.pictureUrl !== null) this.imgList.push(item.pictureUrl)
                        switch (item.publishStatus) {
                            case 0:
                                item.publishStatus = '待上架'
                                break
                            case 1:
                                item.publishStatus = '下架'
                                break
                            case 2:
                                item.publishStatus = '上架'
                                break
                        }
                    })
                    switch (this.seachForm.type) {
                        case 0:
                            this.bigRobeTab = res.data.data.data
                            break
                        case 1:
                            this.kaftenTab = res.data.data.data
                            break
                    }
                }
            })
        },
        handleFinSizeChange (newSize) {
            this.seachForm.pageSize = newSize
            this.seachData()
        },
        handleFinCurrentChange (newNum) {
            this.seachForm.pageNo = newNum
            this.seachData()
        },
        handleSizeChange (newSize) {
            this.seachCodeForm.pageSize = newSize
            this.seachCodeData()
        },
        handleCurrentChange (newNum) {
            this.seachCodeForm.pageNo = newNum
            this.seachCodeData()
        },
        handleStyleSizeChange (newSize) {
            this.seachStyleForm.pageSize = newSize
            this.checkStyleId()
        },
        handleStyleCurrentChange (newNum) {
            this.seachStyleForm.pageNo = newNum
            this.checkStyleId()
        },
        getSrcList(index) {
            return this.imgList.slice(index).concat(this.imgList.slice(0, index))
        },
        // 展示添加框
        showAddData () {
            this.addOrDrop = true
            this.addRobeItemDialogVisible = true
        },
        checkStyleId() {
            getRobeItemList(this.seachForm).then(res => {
                if (res.data.code == 0) {
                    res.data.data.data.forEach(item => {
                        switch (item.newStatus) {
                            case 0:
                                item.newStatus = '非新品'
                                break
                            case 1:
                                item.newStatus = '新品'
                                break
                        }
                        switch (item.hotStatus) {
                            case 0:
                                item.hotStatus = '非热卖'
                                break
                            case 1:
                                item.hotStatus = '热卖'
                                break
                        }
                        switch (item.publishStatus) {
                            case 0:
                                item.publishStatus = '待上架'
                                break
                            case 1:
                                item.publishStatus = '下架'
                                break
                            case 2:
                                item.publishStatus = '上架'
                                break
                        }
                    })
                    this.bigRobeStyleTab = res.data.data.data
                    this.totalStyle = res.data.data.hits
                    this.stylusDialogVisible = true
                }
            })
        },
        getNewClotheMat() {
            getClotheMatForProductAdd(JSON.stringify(this.seachCodeForm)).then(res => {
                if (res.data.code == 0) {
                    this.totalCode = res.data.data.hits
                    this.codeRuleTab = res.data.data.data
                }
            })
        },
        showMatListDlog() {
            this.getNewClotheMat()
            switch (this.addOrDrop) {
                case true:
                    switch (this.activeName) {
                        case '0':
                            this.seachCodeForm.bh = 'C01'
                            break
                        case '1':
                            this.seachCodeForm.bh = 'C02'
                            break
                    }
                    this.matlistDialogVisible = true
                    break
                case false:
                    this.matlistFabDialogVisible = true
                    break
            }
        },
        seachStyleData() {},
        showAddDlog() {},
        handleStyleIdChange(row) {
            if (!row) return
            switch (this.doType) {
                case 0:
                    this.addDataForm.itemId = row.id
                    this.addDataItemName = row.itemCode
                    break
                case 1:
                    this.editDataForm.styleId = row.id
                    break
            }
        },
        // 添加
        addData() {
            this.addDataForm.products = this.proRobeList
            if (this.addDataForm.itemId == '') return this.$message.warning('请选择款号')
            if (this.addDataForm.products == []) return this.$message.warning('请选择编码')
            addProduct(JSON.stringify(this.addDataForm)).then(res => {
                if (res.data.code == 0) {
                    this.$message.success('添加成功')
                    this.seachData()
                    this.addRobeItemDialogVisible = false
                }
            })
        },
        addDlogClose() {
            this.addDataForm.itemId = ''
            this.addDataItemName = ''
            this.proRobeIdList = []
            this.proRobeList = []
        },
        // 表格选中处理
        handleSelectionChange (select) {
            this.selTabData = select
        },
        handleStyleSelectionChange(select) {
            this.selStyleTabData = select
        },
        // 导出
        showExport() {
            this.exportForm.type = this.seachForm.type
            this.exportForm.itemCode = this.seachForm.itemCode
            this.exportForm.bomCode = this.seachForm.bomCode
            this.exportForm.styleName = this.seachForm.styleName
            this.exportForm.title = this.seachForm.title
            this.exportForm.deleteStatus = this.seachForm.deleteStatus
            this.exportForm.publishStatus = this.seachForm.publishStatus
            this.exportDialogVisible = true
        },
        exportData () {
            exportProduct(this.exportForm).then(res => {
                if (res.status == 200) {
                    let date = new Date()
                    let fileType = ''
                    switch (this.exportForm.type) {
                        case 0:
                            fileType = '大袍'
                            break
                        case 1:
                            fileType = 'kaften'
                            break
                    }
                    let name = fileType + "成品" + date.getFullYear() + (date.getMonth() + 1) + date.getDate() + ".xls"
                    let blob = new Blob([res.data], {type: 'application/vnd.ms-excel;charset=utf-8'})
                    let url = window.URL.createObjectURL(blob);
                    let aLink = document.createElement("a");
                    aLink.style.display = 'none';
                    aLink.href = url;
                    aLink.setAttribute('download', name);
                    document.body.appendChild(aLink);
                    aLink.click();
                    document.body.removeChild(aLink); //下载完成移除元素
                    window.URL.revokeObjectURL(url); //释放掉blob对象
                    this.exportDialogVisible = false
                    this.$message.success('导出成功')
                }
            })
        },
        // 上下架
        showPutOrPullData(type) {
            if (this.selTabData.length === 0) {
                this.$message.error(this.$t('plsselthepro'))
                return
            }
            switch (type) {
                case 1:
                    this.putOrPullDataForm.publishStatus = type
                    this.pullDialogVisible = true
                    break
                case 2:
                    this.putOrPullDataForm.publishStatus = type
                    this.putDialogVisible = true
            }
        },
        putData () {
            let isTure = this.selTabData.some(item => {
                this.putOrPullDataForm.ids.push(item.id)
                return item.publishStatus == '上架'
            })
            if (isTure) {
                this.putOrPullDataForm.ids = []
                this.putDialogVisible = false
                return this.$message.error('包含已上架款式，请重新选择')
            }
            updatePublishStatus(JSON.stringify(this.putOrPullDataForm)).then(res => {
                if (res.data.code == 0) {
                    this.$message.success('上架成功')
                    this.putDialogVisible = false
                    this.seachData()
                    switch (this.activeName) {
                        case '0':
                            this.$refs.robeTable.clearSelection()
                            break
                        case '1':
                            this.$refs.kaftenTable.clearSelection()
                            break
                    }
                }
            })

        },
        pullData () {
            let isTure = this.selTabData.some(item => {
                this.putOrPullDataForm.ids.push(item.id)
                return item.publishStatus == '下架'
            })
            if (isTure) {
                this.putOrPullDataForm.ids = []
                this.pullDialogVisible = false
                return this.$message.error('包含已下架款式，请重新选择')
            }
            updatePublishStatus(JSON.stringify(this.putOrPullDataForm)).then(res => {
                if (res.data.code == 0) {
                    this.$message.success('下架成功')
                    this.pullDialogVisible = false
                    this.seachData()
                    switch (this.activeName) {
                        case '0':
                            this.$refs.robeTable.clearSelection()
                            break
                        case '1':
                            this.$refs.kaftenTable.clearSelection()
                            break
                    }
                }
            })
        },
        putOrPullDlogClose() {
            this.putOrPullDataForm.ids = []
        },
        // 修改
        showEditDlog(item) {
            this.editForm.size = item.size
            this.editForm.colour = item.colour
            this.editForm.pic = item.pic
            this.editForm.id = item.id
            this.editForm.price = item.price
            this.editForm.bomCode = item.bomCode
            if (item.pic !== '' && item.pic !== null) this.fileList.push({ name: item.title, url: item.pic })
            this.dialogTableVisible = true
        },
        // 删除
        showDelData () {
            if (this.selTabData.length === 0) {
                this.$message.error(this.$t('plsselthepro'))
                return
            }
            this.selTabData.forEach(item => {
                this.delItem.uuidS.push(item.id)
            })
            this.delDialogVisible = true
        },
        showDelDlog(id) {
            this.delItem.uuidS.push(id)
            this.delDialogVisible = true
        },
        delData () {
            deleteProduct(JSON.stringify(this.delItem)).then(res => {
                if (res.data.code == 0) {
                    this.$message.success(this.$t('delsuc'))
                    this.seachData()
                    this.delDialogVisible = false
                    switch (this.activeName) {
                        case '0':
                            this.$refs.robeTable.clearSelection()
                            break
                        case '1':
                            this.$refs.kaftenTable.clearSelection()
                            break
                    }
                }
            })
        },
        deleteItemDlogClose() {
            this.delItem.uuidS = []
        },
        // 获取推荐数据
        getRecommend () {
            this.dialogTableVisible = true
        },
        editData () {
            if (this.editForm.colour == '') return this.$message.warning('颜色不能为空')
            if (this.editForm.price == '') return this.$message.warning('价格不能为空')
            if (this.editForm.size == '') return this.$message.warning('尺码不能为空')
            updateProduct(JSON.stringify(this.editForm)).then(res => {
                if (res.data.code == 0) {
                    this.$message.success('修改成功')
                    this.dialogTableVisible = false
                    this.seachData()
                }
            })
            this.editDialogTableVisible = false
        },
        editDlogClose() {
            this.editForm.size = ''
            this.editForm.colour = ''
            this.editForm.pic = ''
            this.editForm.id = ''
            this.editForm.price = ''
            this.editForm.bomCode = ''
            this.fileList = []
            this.$refs.sunsetstrip.clearFiles()
        },
        // 图片上传处理
        handleImg(res) {
            if (res.code == 0) {
                this.editForm.pic = res.data
            }
        },
        handleRemove(file) {
            if (file) {
                this.editDataForm.pic = ''
            }
        },
        // 图片上传个数超出处理
        beyond () {
            this.$message.error(this.$t('thenumofpicuplexc'))
        },
        matDafultClose() {
            this.$refs.codeRuleTable.clearSelection()
        },
        handleMatSelectionChange(select) {
            this.selMatTabData = select
        },
        jonyCheck() {
            this.proRobeIdList = []
            this.proRobeList = []
            this.selMatTabData.forEach(item => {
                item.bomCode = item.bh
                item.price = item.up
                item.pic = item.pictureUrl
                item.size = item.spec
                item.colour = item.color
                delete item.bh
                delete item.brand
                delete item.color
                delete item.createTime
                delete item.delete_status
                delete item.name
                delete item.pictureUrl
                delete item.uuid
                delete item.updateTime
                delete item.up
                delete item.unit
                delete item.type
                delete item.spec
                delete item.remark
                this.proRobeIdList.push(item.bomCode)
                this.proRobeList.push(item)
            })
            this.matlistDialogVisible = false
        },
        seachCodeData() {
            switch (this.addOrDrop) {
                case true:
                    switch (this.activeName) {
                        case '0':
                            if (this.seachCodeForm.bh.length < 3) this.seachCodeForm.bh = 'C01'
                            if (this.seachCodeForm.bh.length >= 3) {
                                let isTrue = this.seachCodeForm.bh.slice(0, 3)
                                switch (isTrue) {
                                    case 'C01':
                                        break
                                    default:
                                        this.seachCodeForm.bh = 'C01'
                                        break
                                }
                            }
                            break
                        case '1':
                            if (this.seachCodeForm.bh.length < 3) this.seachCodeForm.bh = 'C02'
                            if (this.seachCodeForm.bh.length >= 3) {
                                let isTrue = this.seachCodeForm.bh.slice(0, 3)
                                switch (isTrue) {
                                    case 'C02':
                                        break
                                    default:
                                        this.seachCodeForm.bh = 'C02'
                                        break
                                }
                            }
                            break
                    }
                    break
                case false:
                    if (this.seachCodeForm.bh.length <= 1) this.seachCodeForm.bh = 'F'
                    if (this.seachCodeForm.bh.length > 1) {
                        let isTrue = this.seachCodeForm.bh.slice(0, 1)
                        switch (isTrue) {
                            case 'F':
                                break
                            default:
                                this.seachCodeForm.bh = 'F'
                                break
                        }
                    }
                    break
            }
            this.getNewClotheMat()
        },
        stylusDlogClose() {},
        // 编码相关
        switchAddMode() {
            this.getMatEnCode()
            this.addItemDialogVisible = true
        },
        addItemDlogClose() {
            this.matEncode.level = 3
            this.matEncode.type = 'clothe'
            this.matEncode.parentNode = 'C01'
            this.getMatEnCode()
            this.firstValue = ''
            this.showParamFlag = false
            this.addLiveType.name = ''
            this.addLiveType.bh = ''
            this.addLiveType.color = ''
            this.addLiveType.spec = ''
            this.addLiveType.brand = 'astre'
            this.addLiveType.type = ''
            this.addLiveType.up = ''
            this.addLiveType.unit = 'pcs'
            this.addLiveType.remark = ''
            if (this.firClickNode !== '') {
                this.$refs[this.firClickNode][0].style.background = '#fff'
                this.$refs[this.firClickNode][0].style['color'] = '#606266'
            }
            this.firClickNode = ''
            this.secClickNode = ''
            this.thrClickNode = ''
            this.fourClickNode = ''
            this.fifClickNode = ''
        },
        getMatEnCode() {
            getMatCode(JSON.stringify(this.matEncode)).then(res => {
                if (res.data.code == 0) {
                    switch (this.matEncode.level) {
                        case 1:
                            this.secondFlag = false;
                            this.thirdFlag = false;
                            this.fourthFlag = false;
                            this.fifFlag = false;
                            res.data.data.forEach(item => {
                                item.label = item.code + '-' + item.name
                            })
                            this.firstColumn = res.data.data;
                            break;
                        case 2:
                            this.secondFlag = true;
                            this.thirdFlag = false;
                            this.fourthFlag = false;
                            this.fifFlag = false;
                            res.data.data.forEach(item => {
                                item.label = item.code + '-' + item.name
                            })
                            this.secondColumn = res.data.data;
                            break;
                        case 3:
                            this.thirdFlag = true;
                            this.fourthFlag = false;
                            this.fifFlag = false;
                            res.data.data.forEach(item => {
                                item.label = item.code + '-' + item.name
                            })
                            this.thirdColumn = res.data.data;
                            break;
                        case 4:
                            this.fourthFlag = true;
                            this.fifFlag = false;
                            res.data.data.forEach(item => {
                                item.label = item.code + '-' + item.name
                            })
                            this.fourthColumn = res.data.data;
                            break;
                        case 5:
                            this.fifFlag = true
                            if (this.matEncode.type == 'wrapper') this.fifFlag = false;
                            res.data.data.forEach(item => {
                                item.label = item.code + '-' + item.name
                            })
                            this.fifColumn = res.data.data;
                            break;
                    }
                }
            })
        },
        getNextEncode(seleteType, node, level, type) {
            this.showParamFlag = false
            switch (seleteType) {
                case 1:
                    // this.keyValue = this.firstValue.split('-')[0]
                    // this.matEncode.parentNode = this.firstValue.split('-')[0]
                    // this.matEncode.level = parseInt(this.firstValue.split('-')[1]) + 1
                    // this.matEncode.type = this.firstValue.split('-')[2]
                    this.$refs[node][0].style.background = '#515775'
                    this.$refs[node][0].style['color'] = '#fff'
                    if (this.firClickNode !== node && this.firClickNode !== '') {
                        this.$refs[this.firClickNode][0].style.background = '#fff'
                        this.$refs[this.firClickNode][0].style['color'] = '#515775'
                    }
                    if (this.secClickNode !== node && this.secClickNode != '') {
                        this.$refs[this.secClickNode][0].style.background = '#fff'
                        this.$refs[this.secClickNode][0].style['color'] = '#515775'
                    }
                    this.thirdFlag = false;
                    this.fourthFlag = false;
                    this.fifFlag = false;
                    this.keyValue = node
                    this.matEncode.parentNode = node
                    this.matEncode.level = level + 1
                    this.matEncode.type = type
                    this.secondParNode = this.matEncode.parentNode
                    this.getMatEnCode()
                    this.isAddFlag = true
                    this.secondValue = ''
                    this.thirdValue = ''
                    this.fourthValue = ''
                    this.fifValue = ''
                    this.createLastNode = node
                    this.firClickNode = node
                    this.secClickNode = ''
                    this.thrClickNode = ''
                    this.fourClickNode = ''
                    this.fifClickNode = ''
                    // this.createLastNode = this.firstValue.split('-')[0]
                    break
                case 2:
                    // this.matEncode.parentNode = this.secondValue.split('-')[0]
                    // this.matEncode.level = parseInt(this.secondValue.split('-')[1]) + 1
                    // this.matEncode.type = this.secondValue.split('-')[2]
                    this.$refs[node][0].style.background = '#515775'
                    this.$refs[node][0].style['color'] = '#fff'
                    if (this.secClickNode !== node && this.secClickNode !== '') {
                        this.$refs[this.secClickNode][0].style.background = '#fff'
                        this.$refs[this.secClickNode][0].style['color'] = '#515775'
                    }
                    if (this.thrClickNode !== node && this.thrClickNode !== '') {
                        this.$refs[this.thrClickNode][0].style.background = '#fff'
                        this.$refs[this.thrClickNode][0].style['color'] = '#515775'
                    }
                    this.fourthFlag = false;
                    this.fifFlag = false;
                    this.matEncode.parentNode = node
                    this.matEncode.level = level + 1
                    this.matEncode.type = type
                    this.thirdParNode = this.matEncode.parentNode
                    this.getMatEnCode()
                    this.isAddFlag = true
                    this.thirdValue = ''
                    this.fourthValue = ''
                    this.createLastNode = node
                    this.secClickNode = node
                    this.thrClickNode = ''
                    this.fourClickNode = ''
                    this.fifClickNode = ''
                    // this.createLastNode = this.secondValue.split('-')[0]
                    this.fifValue = ''
                    break
                case 3:
                    // this.matEncode.parentNode = this.thirdValue.split('-')[0]
                    // this.matEncode.level = parseInt(this.thirdValue.split('-')[1]) + 1
                    // this.matEncode.type = this.thirdValue.split('-')[2]
                    this.$refs[node][0].style.background = '#515775'
                    this.$refs[node][0].style['color'] = '#fff'
                    if (this.thrClickNode !== '' && this.thrClickNode !== node) {
                        this.$refs[this.thrClickNode][0].style.background = '#fff'
                        this.$refs[this.thrClickNode][0].style['color'] = '#515775'
                    }
                    if (this.fourClickNode !== '' && this.fourClickNode !== node) {
                        this.$refs[this.fourClickNode][0].style.background = '#fff'
                        this.$refs[this.fourClickNode][0].style['color'] = '#515775'
                    }
                    this.fifFlag = false;
                    this.matEncode.parentNode = node
                    this.matEncode.level = level + 1
                    this.matEncode.type = type
                    this.fourthParNode = this.matEncode.parentNode
                    this.getMatEnCode()
                    this.isAddFlag = true
                    this.fourthValue = ''
                    this.createLastNode = node
                    this.thrClickNode = node
                    this.fourClickNode = ''
                    this.fifClickNode = ''
                    // this.createLastNode = this.thirdValue.split('-')[0]
                    this.fifValue = ''
                    break
                case 4:
                    // this.matEncode.parentNode = this.fourthValue.split('-')[0]
                    // this.matEncode.level = parseInt(this.fourthValue.split('-')[1]) + 1
                    // this.matEncode.type = this.fourthValue.split('-')[2]
                    this.$refs[node][0].style.background = '#515775'
                    this.$refs[node][0].style['color'] = '#fff'
                    if (this.fourClickNode !== '' && this.fourClickNode !== node) {
                        this.$refs[this.fourClickNode][0].style.background = '#fff'
                        this.$refs[this.fourClickNode][0].style['color'] = '#515775'
                    }
                    if (this.fifClickNode !== '' && this.fifClickNode !== node) {
                        this.$refs[this.fifClickNode][0].style.background = '#fff'
                        this.$refs[this.fifClickNode][0].style['color'] = '#515775'
                    }
                    this.matEncode.parentNode = node
                    this.matEncode.level = level + 1
                    this.matEncode.type = type
                    this.fifthParNode = this.matEncode.parentNode
                    this.getMatEnCode()
                    this.isAddFlag = true
                    this.createLastNode = node
                    this.fourClickNode = node
                    this.fifClickNode = ''
                    // this.createLastNode = this.fourthValue.split('-')[0]
                    this.fifValue = ''
                    break
                case 5:
                    this.$refs[node][0].style.background = '#515775'
                    this.$refs[node][0].style['color'] = '#fff'
                    if (this.fifClickNode !== '' && this.fifClickNode !== node) {
                        this.$refs[this.fifClickNode][0].style.background = '#fff'
                        this.$refs[this.fifClickNode][0].style['color'] = '#515775'
                    }
                    this.createLastNode = node
                    this.fifClickNode = node
                    // this.createLastNode = this.fifValue.split('-')[0]
                    this.isAddFlag = false
                    break
            }
        },
        addDataShow(level) {
            switch (level) {
                case 1:
                    this.addRootCode.level = level;
                    this.addBaseDialogVisible = true
                    break;
                case 2:
                    this.addRootCode.level = level;
                    this.addRootCode.type = this.matEncode.type
                    this.addRootCode.parentNode = this.secondParNode
                    getMaxNumFromChild(JSON.stringify({ node: this.secondParNode })).then(res => {
                        if (res.data.code == 0) {
                            this.addRootCode.code = res.data.data
                        }
                    })
                    this.addDialogVisible=true
                    break;
                case 3:
                    this.addRootCode.level = level;
                    this.addRootCode.type = this.matEncode.type
                    this.addRootCode.parentNode = this.thirdParNode
                    getMaxNumFromChild(JSON.stringify({ node: this.thirdParNode })).then(res => {
                        if (res.data.code == 0) {
                            this.addRootCode.code = res.data.data
                        }
                    })
                    this.addDialogVisible=true
                    break;
                case 4:
                    this.addRootCode.level = level;
                    this.addRootCode.type = this.matEncode.type
                    this.addRootCode.parentNode = this.fourthParNode
                    getMaxNumFromChild(JSON.stringify({ node: this.fourthParNode })).then(res => {
                        if (res.data.code == 0) {
                            this.addRootCode.code = res.data.data
                        }
                    })
                    this.addDialogVisible=true
                    break;
                case 5:
                    this.addRootCode.level = level;
                    this.addRootCode.type = this.matEncode.type
                    this.addRootCode.parentNode = this.fifthParNode
                    getMaxNumFromChild(JSON.stringify({ node: this.fifthParNode })).then(res => {
                        if (res.data.code == 0) {
                            this.addRootCode.code = res.data.data
                        }
                    })
                    this.addDialogVisible=true
                    break;
            }
        },
        addBaseDlogClose(form) {
            this.$refs[form].resetFields();
        },
        addMatEncode(form) {
            this.$refs[form].validate((valid) => {
                if (!valid) return;
                addParMatCode(JSON.stringify(this.addRootCode)).then(res => {
                    if (res.data.code == 0) {
                        this.$message({
                            type: 'success',
                            message: this.$t('newmaterialcategoryadded')
                        })
                        this.addDialogVisible = false
                        this.matEncode.parentNode = this.addRootCode.parentNode
                        this.matEncode.level = this.addRootCode.level
                        this.getMatEnCode()
                    }
                })
            })
        },
        addBaseMatEncode(form) {
            this.$refs[form].validate((valid) => {
                if (!valid) return;
                addParMatCode(JSON.stringify(this.addBaseRootCode)).then(res => {
                    if (res.data.code == 0) {
                        this.$message({
                            type: 'success',
                            message: this.$t('newmaterialcategoryadded')
                        })
                        this.addBaseDialogVisible = false
                        this.matEncode.parentNode = this.addBaseRootCode.parentNode
                        this.matEncode.level = this.addBaseRootCode.level
                        this.getMatEnCode()
                    }
                })
            })
        },
        createCode() {
            updateParMatCode(JSON.stringify({ node: this.createLastNode })).then(res => {
                if (res.data.code == 0) {
                    this.$message({
                        type: 'success',
                        message: this.$t('creatingasuccessful')
                    })
                    this.showParamFlag = true
                    this.addLiveType.bh = res.data.data
                    this.addLiveType.type = this.matEncode.type
                    this.isAddFlag = true
                }
            })
        },
        saveModeCode() {
            insertMatDetail(JSON.stringify(this.addLiveType)).then(res => {
                if (res.data.code == 0) {
                    this.$message({
                        type: 'success',
                        message: this.$t('sucadd')
                    })
                    this.addMode = false
                    this.addItemDialogVisible = false
                    this.getNewClotheMat()
                }
            })
        },
        // 图片上传
        scotland() {
            this.$message.warning('只能选择一个文件')
        },
        handleCodeImg(res) {
            if (res.code == 0) {
                this.addLiveType.pictureUrl = res.data
            }
        },
        hadleRemove(file) {
            if (file) {
                this.addLiveType.pictureUrl = ''
            }
        },
        // 生成吊牌
        showDropDlog(data) {
            this.dropForm.itemCode = data.itemCode
            this.dropForm.colour = data.colour
            this.dropForm.size = data.size
            this.dropForm.price = data.price
            this.dropForm.id = data.id
            this.addOrDrop = false
            this.seachCodeForm.bh = 'F'
            this.dropDataDialogVisible = true
        },
        dropDlogClose() {
            this.fabDataItemName = ''
            this.dropForm.ingredient = ''
            this.dropForm.fabricId = ''
        },
        dropData() {
            createProductTag(JSON.stringify(this.dropForm)).then(res => {
                if (res.data.code == 0) {
                   this.dropUrl = res.data.data
                   this.$message.success('生成成功')
                   this.dropDataDialogVisible = false
                   this.dropImgDialogVisible = true
                }
            })
        },
        handleDropIdChange(row) {
            if (!row) return
            this.dropForm.fabricId = row.uuid
            this.fabDataItemName = row.bh
        },
        jayCheck() {
            this.matlistFabDialogVisible = false
        },
        // 吊牌图片下载
        dropImgClose() {
            this.dropUrl = ''
        },
        downloadByBlob(url,name) {
            let image = new Image()
            image.setAttribute('crossOrigin', 'anonymous')
            image.src = '/fz-web' + url.split('fz-web')[1]
            image.onload = () => {
                let canvas = document.createElement('canvas')
                canvas.width = image.width
                canvas.height = image.height
                let ctx = canvas.getContext('2d')
                ctx.drawImage(image, 0, 0, image.width, image.height)
                canvas.toBlob((blob) => {
                    let url = window.URL.createObjectURL(blob)
                    this.download(url,name)
                    // 用完释放URL对象
                    window.URL.revokeObjectURL(url)
                })
            }
        },
        download(href, name) {
           let eleLink = document.createElement('a')
           eleLink.download = name
           eleLink.href = href
           eleLink.click()
           eleLink.remove()
           this.$message.success('下载完成')
           this.dropImgDialogVisible = false
        }
    },
    mounted () {
        this.seachData()
    }
}
</script>

<style lang="less" scoped>
@import './finishedPro.less';
</style>
